<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Services\UserService;
use App\Requests\UserRequest;
use Illuminate\Http\Request;

/**
 * Copyright (C), 2021-2021, old_liu_cms.
 * FileName: ${FILE_NAME}
 * Description: 说明
 *
 * @author old_liu_cms
 * @Create Date    2021/10/10 14:09
 * @Update Date    2021/10/10 14:09 By head_img
 * @version v1.0
 */
class AuthController extends Controller
{
    protected $service;
    protected $request;

    /**
     * AuthController constructor.
     * @param UserService $service
     * @param Request $request
     */
    public function __construct(UserService $service,Request $request)
    {
        $this->middleware('jwt.users', ['except' => ['login']]);
        $this->service = $service;
        $this->request = $request;
    }


    /**
     * FunctionName：login
     * Description：
     * Author：old_liu_cms
     * @param UserRequest $request
     * @return array
     */
    public function login(UserRequest $request)
    {
        $request->validate('login');
        return $this->service->login($request->only(['user_name','password']));

    }

    /**
     * FunctionName：info
     * Description：
     * Author：old_liu_cms
     * @return object
     */
    public function info()
    {
        return $this->service->info();
    }

    /**
     * FunctionName：logout
     * Description：
     * Author：old_liu_cms
     * @return array|void
     */
    public function logout()
    {
        return $this->service->logout();
    }

    /**
     * FunctionName：updatePassword
     * Description：
     * Author：old_liu_cms
     * @param UserRequest $request
     * @return array|null
     */
    public function updatePassword(UserRequest $request)
    {
        $request->validate('update_password');
        $password = $request->input('password');
        return $this->service->updatePassword($password);
    }

    /**
     * FunctionName：updateInfo
     * Description：
     * Author：old_liu_cms
     * @return array|null
     */
    public function updateInfo()
    {
        return $this->service->updateInfo($this->request->only(['nickname','head_img','city','sex','nickname']));
    }
}
